package com.dpteam.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created with IntelliJ IDEA.
 * User: luolei
 * Date: 2016/1/12
 * Time: 13:42
 */
public class InputCheckUtil {

    private static Pattern pattern;
    /**
     * 邮箱格式
     */
    private static final String emailRegex = "^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\\.[a-zA-Z0-9_-]{2,3}){1,2})$";
    /**
     * 手机号格式
     */
    private static final String phoneRegex = "^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\\d{8}$";
    /**
     * 身份证号格式
     */
    private static final String IDCartNoRegex = "^\\d{15}|\\d{18}$";
    /**
     * 用户名格式
     */
    private static final String accountRegex = "^[a-zA-Z][a-zA-Z0-9_]{4,15}$";
    /**
     * 密码格式
     */
    private static final String passwordRegex = "^[a-zA-Z]\\w{5,17}$";
    /**
     * 强密码格式
     */
    private static final String strongPasswordRegex = "^(?=.\\d)(?=.[a-z])(?=.*[A-Z]).{8,10}$";
    /**
     * 日期格式
     */
    private static final String dateRegex = "^\\d{4}-\\d{1,2}-\\d{1,2}";
    /**
     * 12个月的月份
     */
    private static final String monthNumRegex = "^(0?[1-9]|1[0-2])$";
    /**
     * 每月的天数
     */
    private static final String monthDayRegex = "^((0?[1-9])|(([1|2][0,9])|30|31";
    /**
     * 条形码格式
     */
    private static final String barcodeRegex = "^[0-9]+$";
    /**
     * 数字格式
     */
    private static final String numberRegex = "^[0-9]+$";


    /**
     * 判断输入是否为邮箱格式
     *
     * @param email
     * @return
     */
    public static boolean isEmail(String email) {
        pattern = Pattern.compile(emailRegex);
        Matcher matcher = pattern.matcher(email);
        return matcher.matches();
    }

    /**
     * 判断输入手机号是否符合格式
     *
     * @param phone
     * @return
     */
    public static boolean isPhone(String phone) {
        pattern = Pattern.compile(phoneRegex);
        Matcher matcher = pattern.matcher(phone);
        return matcher.matches();
    }

    /**
     * 身份证号格式
     *
     * @param IDCartNo
     * @return
     */
    public static boolean isIDCartNo(String IDCartNo) {
        pattern = Pattern.compile(IDCartNoRegex);
        Matcher matcher = pattern.matcher(IDCartNo);
        return matcher.matches();
    }

    /**
     * 用户名格式
     *
     * @param account
     * @return
     */
    public static boolean isAccount(String account) {
        pattern = Pattern.compile(accountRegex);
        Matcher matcher = pattern.matcher(account);
        return matcher.matches();
    }

    /**
     * 密码格式
     *
     * @param password
     * @return
     */
    public static boolean isPassword(String password) {
        pattern = Pattern.compile(passwordRegex);
        Matcher matcher = pattern.matcher(password);
        return matcher.matches();
    }

    /**
     * 强密码格式
     *
     * @param strongPassword
     * @return
     */
    public static boolean isStrongPassword(String strongPassword) {
        pattern = Pattern.compile(strongPasswordRegex);
        Matcher matcher = pattern.matcher(strongPassword);
        return matcher.matches();
    }

    /**
     * 日期格式
     *
     * @param date
     * @return
     */
    public static boolean isDate(String date) {
        pattern = Pattern.compile(dateRegex);
        Matcher matcher = pattern.matcher(date);
        return matcher.matches();
    }

    /**
     * 12个月的月份
     *
     * @param monthNum
     * @return
     */
    public static boolean isMonthNum(String monthNum) {
        pattern = Pattern.compile(monthNumRegex);
        Matcher matcher = pattern.matcher(monthNum);
        return matcher.matches();
    }

    /**
     * 每月的天数
     *
     * @param monthDay
     * @return
     */
    public static boolean isMonthDay(String monthDay) {
        pattern = Pattern.compile(monthDayRegex);
        Matcher matcher = pattern.matcher(monthDay);
        return matcher.matches();
    }

    /**
     * 条形码格式
     *
     * @param barcode
     * @return
     */
    public static boolean isBarcode(String barcode) {
        pattern = Pattern.compile(barcodeRegex);
        Matcher matcher = pattern.matcher(barcode);
        return matcher.matches();
    }

    /**
     * 数字格式
     */
    public static boolean isNumber(String number) {
        pattern = Pattern.compile(numberRegex);
        Matcher matcher = pattern.matcher(number);
        return matcher.matches();
    }
}
